<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">用户信息</div>
                <div class="layui-card-body" pad15>
                    <div class="layui-form layui-form-pane" lay-filter="{$lay_table}">
                        <input type="hidden" name="id" value="{:array_get($info,'id')}" />
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:#f90c05;">*</span>用户名</label>
                            <div class="layui-input-block">
                                <input type="text" name="account" value="{:array_get($info,'account')}" lay-verify="required" placeholder="请输入用户名"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">密码</label>
                            <div class="layui-input-block">
                                <input type="text" name="password" placeholder="请输入登录密码，不修改留空" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">头像</label>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn attachment-upload-images" data-input="avatar" data-amount="1">上传图片</button>
                                    <div class="layui-inline layui-word-aux"> 最佳尺寸：320px*320px </div>
                                    <div class="layui-upload-list echo-attachment-image-list" id="avatar">
                                        {notempty name="info.avatar"}
                                        <div>
                                            <input type="hidden" name="avatar" value="{:array_get($info,'avatar')}">
                                            <img src="{:array_get($info,'avatar')}">
                                        </div>
                                        {/notempty}
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:#f90c05;">*</span>昵称</label>
                            <div class="layui-input-block">
                                <input type="text" name="nickname" value="{:array_get($info,'nickname')}" lay-verify="required" placeholder="请输入用户昵称"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item" pane>
                            <label class="layui-form-label"><span style="color:#f90c05;">*</span>性别</label>
                            <div class="layui-input-block">
                                {volist name="gender_list" id="v"}
                                <input type="radio" name="gender" lay-filter="type" value="{$key}" title="{$v}" {eq name=":array_get($info,'gender',1)" value="$key" }checked{/eq}>
                                {/volist}
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color:#f90c05;">*</span>手机号</label>
                            <div class="layui-input-block">
                                <input type="text" name="mobile" value="{:array_get($info,'mobile')}" lay-verify="required|phone" placeholder="请输入手机号"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">真实姓名</label>
                            <div class="layui-input-block">
                                <input type="text" name="realname" value="{:array_get($info,'realname')}" placeholder="请输入真实姓名"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">出生日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="birthday" id="birthday" value="{:array_get($info,'birthday')}" placeholder="请选择出生日期" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item" pane>
                            <label class="layui-form-label"><span style="color:#f90c05;">*</span>状态</label>
                            <div class="layui-input-block">
                                {volist name="status_list" id="v"}
                                <input type="radio" name="status" lay-filter="type" value="{$key}" title="{$v}" {eq name=":array_get($info,'status',1)" value="$key" }checked{/eq}>
                                {/volist}
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">审核备注</label>
                            <div class="layui-input-block">
                                <textarea name="remark" placeholder="请输入审核备注" class="layui-textarea">{:array_get($info,'remark')}</textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="button" lay-submit lay-filter="{$lay_btn}" value="确认提交" class="layui-btn">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['index', 'form', 'upload', 'laydate'], function () {
        const $ = layui.$;
        const admin = layui.admin;
        const form = layui.form;
        const upload = layui.upload;
        const laydate = layui.laydate;
        form.render();

        laydate.render({
            elem: '#birthday',
            type: 'date'
        });

        form.on('submit({$lay_btn})', function (obj) {
            const index = parent.layer.getFrameIndex(window.name);
            admin.req({
                url: "{:url('user/editUser')}",
                type: 'post',
                data: obj.field,
                done: function (res) {
                    layer.msg("提交成功", {
                        icon: 1
                    });
                    parent.layui.table.reload('lay-user-index-table'); //重载表格
                    parent.layer.close(index);
                }
            });
        });

        let upload_input = '';
        let upload_amount = '';
        upload.render({
            elem: '.attachment-upload-images',
            url: "{:url('upload/image')}",
            accept: 'images',
            exits: 'jpg|png|jpeg',
            acceptMime: 'image/*',
            size: 2048,
            number: 1,
            method: 'post',
            before: function(obj) {
                var item = this.item;
                upload_input = $(item).data('input');
                upload_amount = $(item).data('amount');
                layer.load();
            },
            done: function(res, index, upload) {
                layer.closeAll('loading');
                let html = "";
                if (upload_amount == 1) {
                    html += '<div> <input type="hidden" name="' + upload_input + '" value="' + res.data.src + '"> ';
                    html += '<img src="' + res.data.src + '"></div>';
                    $("#" + upload_input).html(html);
                } else {
                    html += '<div> <input type="hidden" name="' + upload_input + '[]" value="' + res.data.src + '"> ';
                    html += '<img src="' + res.data.src +
                        '"> <button type="button" class="attachment-del layui-btn layui-btn-primary layui-btn-xs layui-btn-fluid">删除</button></div>';
                    $("#" + upload_input).append(html);
                }
            },
            error: function(index, upload) {
                layer.closeAll('loading');
            }
        });
    });
</script>
